Page({
  data: {
    memberId: '',
    password: '',
    zdLogin: false
  },
  onLoad(){
    this.setData({
      memberId: wx.getStorageSync('memberId'),
      password: wx.getStorageSync('password'),
      zdLogin: wx.getStorageSync('checked'),
    })
  },
  //清空表单
  zhdel() {
    this.setData({
      memberId: ''
    })
  },
  mmdel() {
    this.setData({
      password: ''
    })
  },
  zdcheck(e) {
      this.setData({
        zdLogin:  e.detail.value
      })
  },
  //登录
  login() {

    //登录失败
    if (this.data.memberId == '' || this.data.password == '') {
      wx.showToast({
        title: '账号密码不能为空',
        icon: 'error'
      })
    } else {
      //登录成功
      wx.request({
        url: "http://49.235.35.140:8080/CateringSystem1.0/recruitment/catering/login.do?method=login",
        method: 'post',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          memberId: this.data.memberId,
          password: this.data.password
        },
        success: (res) => {
          if (res.data.responseBody.memberId != '') {
            // u判断自动开关有没打开
            if (this.data.zdLogin) {
              // 保存登录状态
              wx.setStorageSync('memberId', this.data.memberId)
              wx.setStorageSync('password', this.data.password)
              wx.setStorageSync('checked', true)
            } else {
              wx.removeStorageSync('memberId')
              wx.removeStorageSync('password')
              wx.setStorageSync('checked', false)
            }
            // 进入餐台页面
            wx.navigateTo({
              url: '/pages/table/table',
            })
          } else {
            wx.showToast({
              title: '登录失败',
              icon: 'error'
            })
          }
        },
        fail(res) {
          wx.showToast({
            title: '登录失败',
          })
        }
      })
    }
  }


})